package com.test.enumtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 4.身体状况
 */
public enum EnumSGA4 {

    // 1.过去二个星期，患者有下列的问题困扰，使其无法吃的足够
    ANSWER1_1(1, 0, "正常，没有任何限制"),
    ANSWER1_2(2, 1, "与平常的我不同，但日常生活起居还能自我料理"),
    ANSWER1_4(4, 2, "感觉不舒服，但躺在床上的时间不会长于半天"),
    ANSWER1_8(8, 3, "只能做少数活动，大多数时间躺在床上或坐在椅子"),
    ANSWER1_16(16, 3, "绝大多数的时间躺在床上"),
    ;

    public final int id;
    public final int score;
    public final String name;

    EnumSGA4(int id, int score, String name) {
        this.id = id;
        this.score = score;
        this.name = name;
    }

    /**
     * 获取答案列表 1.过去二个星期，患者有下列的问题困扰，使其无法吃的足够
     *
     * @return
     */
    public static List<Map<String, Object>> getAnswerList() {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(createMap(1));
        list.add(createMap(2));
        list.add(createMap(4));
        list.add(createMap(8));
        list.add(createMap(16));
        return list;
    }

    /**
     * 根据id获取枚举
     *
     * @param id
     * @return
     */
    public static EnumSGA4 get(int id) {
        switch (id) {
            case 1:
                return ANSWER1_1;
            case 2:
                return ANSWER1_2;
            case 4:
                return ANSWER1_4;
            case 8:
                return ANSWER1_8;
            case 16:
                return ANSWER1_16;
            default:
                return null;
        }
    }

    /**
     * 根据id获取分数
     *
     * @param id
     * @return
     */
    public static int getScore(int id) {
        EnumSGA4 en = EnumSGA4.get(id);
        if (en != null) {
            return en.score;
        } else {
            return -1;
        }
    }

    private static Map<String, Object> createMap(int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", EnumSGA4.get(id).id);
        map.put("name", EnumSGA4.get(id).name);
        map.put("score", EnumSGA4.get(id).score);
        return map;
    }
}
